require "rake"
require "rake/clean"
require "rake/gempackagetask"
require "rake/rdoctask"
require "fileutils"
include FileUtils

##############################################################################
# Configuration
##############################################################################
NAME = "sequel"
VERS = "1.0"
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
RDOC_OPTS = [
  "--quiet", 
  "--title", "Sequel: Database access for Ruby",
  "--opname", "index.html",
  "--line-numbers", 
  "--main", "README",
  "--inline-source"
]

##############################################################################
# Gem packaging
##############################################################################
desc "Packages up Sequel."
task :default => [:package]
task :package => [:clean]

RDOC_OPTS = [
  "--quiet", 
  "--title", "Sequel Model: Lightweight ORM for Ruby",
  "--opname", "index.html",
  "--line-numbers", 
  "--main", "README",
  "--inline-source"
]

spec = Gem::Specification.new do |s|
  s.name = NAME
  s.rubyforge_project = 'sequel'
  s.version = VERS
  s.platform = Gem::Platform::RUBY
  s.summary = "Database access for Ruby"
  s.description = s.summary
  s.author = "Sharon Rosner"
  s.email = "ciconia@gmail.com"
  s.homepage = "http://sequel.rubyforge.org"
  s.required_ruby_version = ">= 1.8.4"

  s.has_rdoc = true
  s.extra_rdoc_files = ["README", "COPYING"]

  s.add_dependency("sequel_core")
  s.add_dependency("sequel_model")
  
  s.files = %w(Rakefile) + Dir.glob("{lib}/**/*")
  s.require_path = "lib"
end

Rake::GemPackageTask.new(spec) do |p|
  p.need_tar = true
  p.gem_spec = spec
end

##############################################################################
# installation & removal
##############################################################################
task :install do
  sh %{rake package}
  sh %{sudo gem install pkg/#{NAME}-#{VERS}}
end

task :install_no_docs do
  sh %{rake package}
  sh %{sudo gem install pkg/#{NAME}-#{VERS} --no-rdoc --no-ri}
end

task :uninstall => [:clean] do
  sh %{sudo gem uninstall #{NAME}}
end

task :tag do
  cwd = FileUtils.pwd
  sh %{cd ../.. && svn copy #{cwd} tags/#{NAME}-#{VERS} && svn commit -m "#{NAME}-#{VERS} tag." tags}
end

##############################################################################
# gem release
##############################################################################
task :release => [:package] do
  sh %{rubyforge login}
  sh %{rubyforge add_release sequel #{NAME} #{VERS} pkg/#{NAME}-#{VERS}.tgz}
  sh %{rubyforge add_file sequel #{NAME} #{VERS} pkg/#{NAME}-#{VERS}.gem}
end
